﻿using System.Collections.Generic;
using System.Linq;
using Citi.PTSConsolidation.Domain;
using System.ComponentModel.DataAnnotations;

namespace Citi.PTSConsolidation.WebUi.Models
{
    public class PearlAccountMapModel
    {
        public int Id { get; set; }
        
        [MaxLength(150), Required]
        [Display(Name = "Account L14 Description")]
        public string AccountL14Desc { get; set; }

        [MaxLength(15), Required]
        [Display(Name = "Leaf")]
        public string Leaf { get; set; }
        
        [MaxLength(256), Required]
        [Display(Name = "Leaf Description")]
        public string LeafDescr { get; set; }
        
        [MaxLength(50), Required]
        [Display(Name = "Line Type")]
        public string LineType { get; set; }
        
        [MaxLength(100)]
        [Display(Name = "Aditional Rule")]
        public string AditionalRule { get; set; }

        public static PearlAccountMapModel CreateModel(PearlAccountMap domain)
        {
            var model = new PearlAccountMapModel
            {
                AccountL14Desc = domain.AccountL14Desc,
                AditionalRule = domain.AditionalRule,
                Id = domain.Id,
                Leaf = domain.Leaf,
                LeafDescr = domain.LeafDescr,
                LineType = domain.LineType
            };

            return model;
        }

        public static IEnumerable<PearlAccountMapModel> CreateModel(IEnumerable<PearlAccountMap> domain)
        {
            return domain.Select(CreateModel);
        }

        public static PearlAccountMap CreateDomain(PearlAccountMapModel model)
        {
            return new PearlAccountMap
            {
                AccountL14Desc = model.AccountL14Desc,
                AditionalRule = model.AditionalRule,
                Id = model.Id,
                Leaf = model.Leaf,
                LeafDescr = model.LeafDescr,
                LineType = model.LineType
            };
        }

        public static IEnumerable<PearlAccountMap> CreateDomain(IEnumerable<PearlAccountMapModel> model)
        {
            return model.Select(CreateDomain);
        }
    }
}